﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SoundManager : MonoBehaviour {

	public AudioSource efxSource;
	public AudioSource musicSource;
	public static SoundManager instance = null;

	private float lowPitchRange = .95f;
	private float highPitchRange = 1.0f;


	// Use this for initialization
	void Awake () {
		if (instance == null) {
			instance = this;
		}
		else if (instance != this) {
			Destroy (gameObject);
		}
		DontDestroyOnLoad (gameObject);
	}

	public void PlaySingle(AudioClip clip)
	{
		efxSource.clip = clip;
		efxSource.Play ();
	}

	public void RandomizeSfx (params AudioClip[] clip)
	{
		int randomIndex = Random.Range (0, clip.Length);
		float randomPatch = Random.Range (lowPitchRange, highPitchRange);

		efxSource.pitch = randomPatch;
		efxSource.clip = clip[randomIndex];
		efxSource.Play ();
	}
}
